<template>
  <div class="newsinfo-container">
    <h3 class="title" >{{ newsinfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ newsinfo.time }}</span>
      <span>点击：{{ newsinfo.click }}次</span>
    </p>
    <hr>
    <div class="content">
      <p>{{ newsinfo.text }}</p>
      <p>{{ newsinfo.text }}</p>
      <p>{{ newsinfo.text }}</p>
    </div>
    <!-- 评论子组件 -->
    <commment-box></commment-box>
  </div>
</template>

<script>
import { Toast } from 'mint-ui'

// 1.导入评论子组件
import comment from '../subcomponents/comment.vue'
export default {
  data() {
    return {
      id : this.$route.params.id, // 讲URL地址传递过来的ID值，挂载到data上
      newsinfo : []
    }
  },
  created() {
    this.getNewsinfo()
  },
  methods: {
    getNewsinfo(){ //获取新闻详情
      this.$http.get('vuenewslist').then(result => {
        if(result.body){
          // 成功了
          this.newsinfo = result.body[this.id]
        } else {
          Toast('加载新闻详情失败')
        }
      })
    }
  },
// 2.注册子组件的节点
  components: {
    'commment-box' : comment
  }
}
</script>

<style lang="scss" scoped>
.newsinfo-container{
  padding: 4px;
  .title{
    font: 900 18px/25px '宋体';
    text-align: center;
    color:firebrick;
    padding-top: 10px;
  }
  .subtitle{
    font: 13px/20px '宋体';
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding: 5px;
  }
  .content{
    padding: 15px 5px 5px 5px;
    p{
      font: 12px/20px '宋体';
      text-indent: 2em;
      color: #222;
    }

  }
}
</style>
